//
//  SISSHousePriceMapViewController+DataRequest.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/22.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSHousePriceMapViewController+DataRequest.h"
#import "SISSJsonRequestNetworkingManager+Map.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import "SISSMapPriceBottomShowView.h"

@implementation SISSHousePriceMapViewController (DataRequest)

#pragma mark - 请求数据
- (void)requestDataWithMapSearchLevel:(NSString *)mapSearchLevel {
    
    
    // 当前屏幕中心点的经纬度
    CGFloat centerLongitude = self.mapView.region.center.longitude;
    CGFloat centerLatitude = self.mapView.region.center.latitude;
    // 当前屏幕显示范围的经纬度
    CLLocationDegrees pointssLongitudeDelta = self.mapView.region.span.longitudeDelta;
    CLLocationDegrees pointssLatitudeDelta = self.mapView.region.span.latitudeDelta;
    //左上角
    CGFloat leftUpLong = centerLongitude - pointssLongitudeDelta / 2.0;
    CGFloat leftUpLati = centerLatitude - pointssLatitudeDelta / 2.0;
    // 右上角
    CGFloat rightUpLong = centerLongitude + pointssLongitudeDelta / 2.0;
    CGFloat rightUpLati = centerLatitude - pointssLatitudeDelta / 2.0;
    //左下角
    CGFloat leftDownLong = centerLongitude - pointssLongitudeDelta / 2.0;
    CGFloat leftDownlati = centerLatitude + pointssLatitudeDelta / 2.0;
    //右下角
    CGFloat rightDownLong = centerLongitude + pointssLongitudeDelta / 2.0;
    CGFloat rightDownLati = centerLatitude + pointssLatitudeDelta /  2.0;
    
    NSLog(@"\n 左上   %f,%f---------\n 右上   %f,%f-------\n 左下  %f,%f----- \n 右下  %f,%f",leftUpLong,leftUpLati,rightUpLong,rightUpLati,leftDownLong,leftDownlati,rightDownLong,rightDownLati);
    

    NSString *blockNo = self.blockNo ? self.blockNo : @"";
    NSString *maxLon = self.maxLon ? self.maxLon : @"";
    NSString *minLon = self.minLon ? self.minLon : @"";
    NSString *maxLat = self.maxLat ? self.maxLat : @"";
    NSString *minLat = self.minLat ? self.minLat : @"";
    NSString *pname = self.pname ? self.pname : @"";
    NSString *townNo = self.townNo ? self.townNo : @"";
    
    NSDictionary *parameters = @{
                                 @"blockNo": blockNo, // 板块编号
                                 @"mapSearchLevel": mapSearchLevel, // 查询级别 1=城市，2=区域，3=板块
                                 @"maxLon": maxLon, // 最大经度值
                                 @"minLon": minLon, // 最小经度值 查询级别为3时不能为空
                                 @"maxLat": maxLat, // 最大纬度值 查询级别为3时不能为空
                                 @"minLat": minLat, // 最小纬度值 查询级别为3时不能为空
                                 @"pname": pname, // 楼盘名称
                                 @"townNo": townNo // 区域编号
                                 };
    [kJsonRequestNetworkingManager requestFilterMapEvaluationStatisticsResourceWithParameters:parameters success:^(id responseObject) {
        
        if ([mapSearchLevel isEqualToString:@"1"]) {
            NSArray *dataArr = responseObject[@"data"];
            NSArray *mapTownInfoArr = [NSArray yy_modelArrayWithClass:[SISSMapTownInfoModel class] json:dataArr];
            self.mapTownInfoArr = mapTownInfoArr;
            self.firstZoomUpRequestSuccess = NO;
            self.firstZoomDownRequestSuccess = NO;
            [self loadDataWithZoomLevel:12.5];
        } else if ([mapSearchLevel isEqualToString:@"2"]) {
            NSDictionary *dataDict = responseObject[@"data"];
            NSArray *blockInfoList = dataDict[@"blockInfoList"];
            NSDictionary *townInfoDetailDict = dataDict[@"townInfoDetail"];
            NSArray *mapBlockInfoArr = [NSArray yy_modelArrayWithClass:[SISSMapBlockInfoModel class] json:blockInfoList];
            self.mapTownInfoDetailModel = [SISSMapTownInfoDetailModel yy_modelWithJSON:townInfoDetailDict];
            self.mapBlockInfoArr = mapBlockInfoArr;
            self.priceBottomShowView.townInfoDetail = self.mapTownInfoDetailModel;
            self.secondZoomUpRequestSuccess = YES;
            self.secondZoomDownRequestSuccess = YES;
            [self loadDataWithZoomLevel:15];
            self.selectPointShow = NO;
        } else if ([mapSearchLevel isEqualToString:@"3"]) {
            NSDictionary *dataDict = responseObject[@"data"];
            NSArray *buildInfoList = dataDict[@"buildInfoList"];
            NSDictionary *blockInfoDetailDict = dataDict[@"blockInfoDetail"];
            NSArray *mapBuildInfoArr = [NSArray yy_modelArrayWithClass:[SISSMapBuildInfoModel class] json:buildInfoList];
            self.mapBuildInfoArr = mapBuildInfoArr;
            self.mapBlockInfoDetailModel = [SISSMapBlockInfoDetailModel yy_modelWithJSON:blockInfoDetailDict];
            self.priceBottomShowView.blockInfoDetail = self.mapBlockInfoDetailModel;
            [self loadDataWithZoomLevel:17];
            self.selectPointShow = NO;
        }
        
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}


@end
